﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EHRForce.Models
{
    public class PatientRepository
    {
        private EHRForceDataContext db = new EHRForceDataContext();

        //
        // Query Methods

        public IQueryable<Patient> FindAllPatients()
        {
            return db.Patients;
        }

        public Patient GetPatient(int id)
        {
            return db.Patients.SingleOrDefault(d => d.PatientUID == id);
        }

        //
        // Insert/Delete Methods

        public void Add(Patient patient)
        {
            db.Patients.InsertOnSubmit(patient);
        }

        public void Delete(Patient patient)
        {
            db.PtAccounts.DeleteAllOnSubmit(patient.PtAccounts);
            db.Patients.DeleteOnSubmit(patient);
        }

        //
        // Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}